package com.imooc.service.impl;

import com.imooc.mapper.StuMapper;
import com.imooc.pojo.Stu;
import com.imooc.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <h1></h1>
 *
 * @author : dzj
 * @create: 2021-07-19 14:26
 */
@Service
public class StuServiceImpl implements StuService {

    @Autowired
    private StuMapper stuMapper;
    @Override
    public Stu getStuInfo(int stuId) {
        Stu stu = stuMapper.selectByPrimaryKey(stuId);
        return stu;
    }

    @Override
    @Transactional
    public void save(Stu stu) {
        stuMapper.insert(stu);
    }

    @Override
    @Transactional
    public void updateStu(Stu stu) {
        Stu stu1 = stuMapper.selectByPrimaryKey(stu.getId());
        stu1.setName(stu.getName());
        stu1.setAge(stu.getAge());
        stuMapper.updateByPrimaryKey(stu1);
    }

    @Override
    public void deleteStu(int stuId) {
        stuMapper.deleteByPrimaryKey(stuId);
    }

    @Override
    public void saveParent() {

    }

    @Override
    public void saveChildren() {

    }
}
